{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-08-27T00:53:48.742830Z",
     "start_time": "2025-08-27T00:53:44.420191Z"
    }
   },
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.optim as optim\n",
    "from torch.utils.data import Dataset, DataLoader\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import geopandas as gpd\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "\n",
    "import folium\n",
    "\n",
    "print(f\"PyTorch版本: {torch.__version__}\")\n",
    "print(f\"GPU可用: {torch.cuda.is_available()}\")"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PyTorch版本: 2.8.0+cpu\n",
      "GPU可用: False\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-27T00:55:38.573766Z",
     "start_time": "2025-08-27T00:55:38.552766Z"
    }
   },
   "cell_type": "code",
   "source": [
    "class GDPDataset(Dataset):\n",
    "    \"\"\"GDP时间序列数据集\"\"\"\n",
    "    def __init__(self, data, time_steps=5, predict_steps=3):\n",
    "        self.data = data\n",
    "        self.time_steps = time_steps\n",
    "        self.predict_steps = predict_steps\n",
    "        self.scaler = MinMaxScaler()\n",
    "        self.scaled_data = self.scaler.fit_transform(data.values.reshape(-1, 1))\n",
    "        self.X, self.y = self.create_sequences()\n",
    "\n",
    "    def create_sequences(self):\n",
    "        X, y = [], []\n",
    "        for i in range(len(self.scaled_data) - self.time_steps - self.predict_steps + 1):\n",
    "            X.append(self.scaled_data[i:i + self.time_steps, 0])\n",
    "            y.append(self.scaled_data[i + self.time_steps:i + self.time_steps + self.predict_steps, 0])\n",
    "        return torch.FloatTensor(np.array(X)), torch.FloatTensor(np.array(y))\n",
    "\n",
    "    def __len__(self):\n",
    "        return len(self.X)\n",
    "\n",
    "    def __getitem__(self, idx):\n",
    "        return self.X[idx], self.y[idx]\n",
    "\n",
    "    def inverse_transform(self, data):\n",
    "        return self.scaler.inverse_transform(data.reshape(-1, 1)).flatten()\n",
    "\n",
    "# 加载数据\n",
    "# 读取文件，跳过前3行注释\n",
    "df = pd.read_csv('data/original_data/分省年度数据_utf8.csv',\n",
    "                 skiprows=3,\n",
    "                 skipfooter=2,  # 跳过最后2行\n",
    "                 encoding='utf-8',\n",
    "                 engine='python')  # 必须指定engine为python才能使用skipfooter)\n",
    "df.set_index('地区', inplace=True)\n",
    "df = df.astype(float)\n",
    "df_time = df.T\n",
    "\n",
    "print(\"数据加载完成，形状:\", df_time.shape)"
   ],
   "id": "5bde7cbdce08f595",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据加载完成，形状: (10, 31)\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-27T00:58:26.207314Z",
     "start_time": "2025-08-27T00:58:26.202108Z"
    }
   },
   "cell_type": "code",
   "source": [
    "class LSTMPredictor(nn.Module):\n",
    "    \"\"\"LSTM时间序列预测模型\"\"\"\n",
    "    def __init__(self, input_size=1, hidden_size=50, num_layers=2, output_size=3, dropout=0.2):\n",
    "        super(LSTMPredictor, self).__init__()\n",
    "        self.hidden_size = hidden_size\n",
    "        self.num_layers = num_layers\n",
    "\n",
    "        self.lstm = nn.LSTM(input_size, hidden_size, num_layers,\n",
    "                           batch_first=True, dropout=dropout)\n",
    "        self.dropout = nn.Dropout(dropout)\n",
    "        self.fc = nn.Sequential(\n",
    "            nn.Linear(hidden_size, 25),\n",
    "            nn.ReLU(),\n",
    "            nn.Dropout(dropout),\n",
    "            nn.Linear(25, output_size)\n",
    "        )\n",
    "\n",
    "    def forward(self, x):\n",
    "        # x shape: (batch_size, time_steps, input_size)\n",
    "        h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(x.device)\n",
    "        c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size).to(x.device)\n",
    "\n",
    "        out, _ = self.lstm(x, (h0, c0))\n",
    "        out = self.dropout(out[:, -1, :])  # 取最后一个时间步的输出\n",
    "        out = self.fc(out)\n",
    "        return out\n",
    "\n",
    "# 设备配置\n",
    "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
    "print(f\"使用设备: {device}\")"
   ],
   "id": "82323175467d0af7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "使用设备: cpu\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-27T00:58:39.215653Z",
     "start_time": "2025-08-27T00:58:36.967021Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def train_model(model, dataloader, criterion, optimizer, num_epochs=100):\n",
    "    \"\"\"训练模型\"\"\"\n",
    "    model.train()\n",
    "    train_losses = []\n",
    "\n",
    "    for epoch in range(num_epochs):\n",
    "        epoch_loss = 0\n",
    "        for batch_X, batch_y in dataloader:\n",
    "            batch_X, batch_y = batch_X.to(device), batch_y.to(device)\n",
    "\n",
    "            optimizer.zero_grad()\n",
    "            outputs = model(batch_X.unsqueeze(-1))\n",
    "            loss = criterion(outputs, batch_y)\n",
    "            loss.backward()\n",
    "            optimizer.step()\n",
    "\n",
    "            epoch_loss += loss.item()\n",
    "\n",
    "        avg_loss = epoch_loss / len(dataloader)\n",
    "        train_losses.append(avg_loss)\n",
    "\n",
    "        if (epoch + 1) % 20 == 0:\n",
    "            print(f'Epoch [{epoch+1}/{num_epochs}], Loss: {avg_loss:.6f}')\n",
    "\n",
    "    return train_losses\n",
    "\n",
    "def predict_future(model, dataset, province_name, time_steps=5):\n",
    "    \"\"\"预测未来值\"\"\"\n",
    "    model.eval()\n",
    "    with torch.no_grad():\n",
    "        province_data = df_time[province_name]\n",
    "        dataset_province = GDPDataset(province_data, time_steps=time_steps)\n",
    "\n",
    "        # 获取最后的时间序列\n",
    "        last_sequence = dataset_province.scaled_data[-time_steps:, 0]\n",
    "        last_sequence_tensor = torch.FloatTensor(last_sequence).to(device).unsqueeze(0).unsqueeze(-1)\n",
    "\n",
    "        # 预测\n",
    "        prediction = model(last_sequence_tensor)\n",
    "        prediction_actual = dataset_province.inverse_transform(prediction.cpu().numpy())\n",
    "\n",
    "        return prediction_actual\n",
    "\n",
    "# 以北京市为例进行训练和预测\n",
    "beijing_data = df_time['北京市']\n",
    "dataset = GDPDataset(beijing_data, time_steps=5)\n",
    "\n",
    "# 创建数据加载器\n",
    "dataloader = DataLoader(dataset, batch_size=4, shuffle=True)\n",
    "\n",
    "# 初始化模型\n",
    "model = LSTMPredictor().to(device)\n",
    "criterion = nn.MSELoss()\n",
    "optimizer = optim.Adam(model.parameters(), lr=0.001)\n",
    "\n",
    "print(\"开始训练LSTM模型...\")\n",
    "train_losses = train_model(model, dataloader, criterion, optimizer, num_epochs=200)\n",
    "\n",
    "# 预测未来3年\n",
    "predictions = predict_future(model, dataset, '北京市')\n",
    "print(f\"北京市未来3年GDP预测: {predictions}\")\n",
    "\n",
    "# 计算准确率\n",
    "actual_2024 = beijing_data.iloc[-1]\n",
    "predicted_2024 = predictions[0] if len(predictions) > 0 else 0\n",
    "accuracy = (1 - abs(actual_2024 - predicted_2024) / actual_2024) * 100\n",
    "print(f\"预测准确率: {accuracy:.2f}%\")"
   ],
   "id": "a82265daae4430e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始训练LSTM模型...\n",
      "Epoch [20/200], Loss: 0.073836\n",
      "Epoch [40/200], Loss: 0.027801\n",
      "Epoch [60/200], Loss: 0.044671\n",
      "Epoch [80/200], Loss: 0.013722\n",
      "Epoch [100/200], Loss: 0.017094\n",
      "Epoch [120/200], Loss: 0.014824\n",
      "Epoch [140/200], Loss: 0.016207\n",
      "Epoch [160/200], Loss: 0.005701\n",
      "Epoch [180/200], Loss: 0.005356\n",
      "Epoch [200/200], Loss: 0.010252\n",
      "北京市未来3年GDP预测: [30612.594 28285.77  28834.773]\n",
      "预测准确率: 82.41%\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-08-27T00:59:36.566775Z",
     "start_time": "2025-08-27T00:59:18.350940Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def predict_all_provinces(model_type='lstm'):\n",
    "    \"\"\"预测所有省份的未来GDP\"\"\"\n",
    "    predictions_dict = {}\n",
    "    accuracies = {}\n",
    "\n",
    "    for province in df_time.columns:\n",
    "        try:\n",
    "            province_data = df_time[province]\n",
    "\n",
    "            if model_type == 'lstm':\n",
    "                model = LSTMPredictor().to(device)\n",
    "            elif model_type == 'transformer':\n",
    "                model = TransformerPredictor().to(device)\n",
    "            elif model_type == 'tcn':\n",
    "                model = TCNPredictor().to(device)\n",
    "\n",
    "            dataset = GDPDataset(province_data, time_steps=5)\n",
    "            dataloader = DataLoader(dataset, batch_size=4, shuffle=True)\n",
    "\n",
    "            criterion = nn.MSELoss()\n",
    "            optimizer = optim.Adam(model.parameters(), lr=0.001)\n",
    "\n",
    "            # 训练模型\n",
    "            train_model(model, dataloader, criterion, optimizer, num_epochs=150)\n",
    "\n",
    "            # 预测\n",
    "            pred = predict_future(model, dataset, province)\n",
    "            predictions_dict[province] = pred\n",
    "\n",
    "            # 计算准确率（使用最后一年作为验证）\n",
    "            actual_last = province_data.iloc[-1]\n",
    "            predicted_first = pred[0] if len(pred) > 0 else 0\n",
    "            accuracy = (1 - abs(actual_last - predicted_first) / actual_last) * 100\n",
    "            accuracies[province] = accuracy\n",
    "\n",
    "            print(f\"{province}: 准确率 {accuracy:.2f}%\")\n",
    "\n",
    "        except Exception as e:\n",
    "            print(f\"处理 {province} 时出错: {e}\")\n",
    "            continue\n",
    "\n",
    "    return predictions_dict, accuracies\n",
    "\n",
    "print(\"开始批量预测所有省份...\")\n",
    "all_predictions, all_accuracies = predict_all_provinces('lstm')\n",
    "\n",
    "# 统计准确率\n",
    "avg_accuracy = np.mean(list(all_accuracies.values()))\n",
    "print(f\"\\n平均预测准确率: {avg_accuracy:.2f}%\")\n",
    "print(f\"准确率 > 90% 的省份数量: {sum(1 for acc in all_accuracies.values() if acc > 90)}\")"
   ],
   "id": "c6149873002f610d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始批量预测所有省份...\n",
      "Epoch [20/150], Loss: 0.032009\n",
      "Epoch [40/150], Loss: 0.007072\n",
      "Epoch [60/150], Loss: 0.009063\n",
      "Epoch [80/150], Loss: 0.013470\n",
      "Epoch [100/150], Loss: 0.025608\n",
      "Epoch [120/150], Loss: 0.012799\n",
      "Epoch [140/150], Loss: 0.014261\n",
      "北京市: 准确率 77.07%\n",
      "Epoch [20/150], Loss: 0.036594\n",
      "Epoch [40/150], Loss: 0.010103\n",
      "Epoch [60/150], Loss: 0.007826\n",
      "Epoch [80/150], Loss: 0.013800\n",
      "Epoch [100/150], Loss: 0.020498\n",
      "Epoch [120/150], Loss: 0.003263\n",
      "Epoch [140/150], Loss: 0.010751\n",
      "天津市: 准确率 82.66%\n",
      "Epoch [20/150], Loss: 0.026268\n",
      "Epoch [40/150], Loss: 0.011912\n",
      "Epoch [60/150], Loss: 0.023097\n",
      "Epoch [80/150], Loss: 0.005424\n",
      "Epoch [100/150], Loss: 0.010131\n",
      "Epoch [120/150], Loss: 0.009696\n",
      "Epoch [140/150], Loss: 0.011166\n",
      "河北省: 准确率 86.54%\n",
      "Epoch [20/150], Loss: 0.033419\n",
      "Epoch [40/150], Loss: 0.011573\n",
      "Epoch [60/150], Loss: 0.010457\n",
      "Epoch [80/150], Loss: 0.014357\n",
      "Epoch [100/150], Loss: 0.008484\n",
      "Epoch [120/150], Loss: 0.005976\n",
      "Epoch [140/150], Loss: 0.010201\n",
      "山西省: 准确率 78.49%\n",
      "Epoch [20/150], Loss: 0.043566\n",
      "Epoch [40/150], Loss: 0.010183\n",
      "Epoch [60/150], Loss: 0.004581\n",
      "Epoch [80/150], Loss: 0.005598\n",
      "Epoch [100/150], Loss: 0.006399\n",
      "Epoch [120/150], Loss: 0.006210\n",
      "Epoch [140/150], Loss: 0.002931\n",
      "内蒙古自治区: 准确率 83.86%\n",
      "Epoch [20/150], Loss: 0.021653\n",
      "Epoch [40/150], Loss: 0.018406\n",
      "Epoch [60/150], Loss: 0.009358\n",
      "Epoch [80/150], Loss: 0.011017\n",
      "Epoch [100/150], Loss: 0.010770\n",
      "Epoch [120/150], Loss: 0.009791\n",
      "Epoch [140/150], Loss: 0.007300\n",
      "辽宁省: 准确率 89.89%\n",
      "Epoch [20/150], Loss: 0.013846\n",
      "Epoch [40/150], Loss: 0.009890\n",
      "Epoch [60/150], Loss: 0.006176\n",
      "Epoch [80/150], Loss: 0.011030\n",
      "Epoch [100/150], Loss: 0.004876\n",
      "Epoch [120/150], Loss: 0.005771\n",
      "Epoch [140/150], Loss: 0.001774\n",
      "吉林省: 准确率 92.23%\n",
      "Epoch [20/150], Loss: 0.015267\n",
      "Epoch [40/150], Loss: 0.008672\n",
      "Epoch [60/150], Loss: 0.010253\n",
      "Epoch [80/150], Loss: 0.008094\n",
      "Epoch [100/150], Loss: 0.008230\n",
      "Epoch [120/150], Loss: 0.014984\n",
      "Epoch [140/150], Loss: 0.005685\n",
      "黑龙江省: 准确率 98.10%\n",
      "Epoch [20/150], Loss: 0.129258\n",
      "Epoch [40/150], Loss: 0.028752\n",
      "Epoch [60/150], Loss: 0.025700\n",
      "Epoch [80/150], Loss: 0.026937\n",
      "Epoch [100/150], Loss: 0.018378\n",
      "Epoch [120/150], Loss: 0.035743\n",
      "Epoch [140/150], Loss: 0.045869\n",
      "上海市: 准确率 75.33%\n",
      "Epoch [20/150], Loss: 0.057148\n",
      "Epoch [40/150], Loss: 0.011290\n",
      "Epoch [60/150], Loss: 0.016601\n",
      "Epoch [80/150], Loss: 0.008919\n",
      "Epoch [100/150], Loss: 0.009020\n",
      "Epoch [120/150], Loss: 0.008099\n",
      "Epoch [140/150], Loss: 0.011595\n",
      "江苏省: 准确率 79.50%\n",
      "Epoch [20/150], Loss: 0.007985\n",
      "Epoch [40/150], Loss: 0.014796\n",
      "Epoch [60/150], Loss: 0.011177\n",
      "Epoch [80/150], Loss: 0.012380\n",
      "Epoch [100/150], Loss: 0.008073\n",
      "Epoch [120/150], Loss: 0.003824\n",
      "Epoch [140/150], Loss: 0.012572\n",
      "浙江省: 准确率 83.63%\n",
      "Epoch [20/150], Loss: 0.027337\n",
      "Epoch [40/150], Loss: 0.020938\n",
      "Epoch [60/150], Loss: 0.012557\n",
      "Epoch [80/150], Loss: 0.013192\n",
      "Epoch [100/150], Loss: 0.014802\n",
      "Epoch [120/150], Loss: 0.013183\n",
      "Epoch [140/150], Loss: 0.017256\n",
      "安徽省: 准确率 69.24%\n",
      "Epoch [20/150], Loss: 0.027347\n",
      "Epoch [40/150], Loss: 0.012188\n",
      "Epoch [60/150], Loss: 0.008925\n",
      "Epoch [80/150], Loss: 0.021114\n",
      "Epoch [100/150], Loss: 0.015399\n",
      "Epoch [120/150], Loss: 0.029362\n",
      "Epoch [140/150], Loss: 0.012288\n",
      "福建省: 准确率 66.03%\n",
      "Epoch [20/150], Loss: 0.010819\n",
      "Epoch [40/150], Loss: 0.019939\n",
      "Epoch [60/150], Loss: 0.007144\n",
      "Epoch [80/150], Loss: 0.006934\n",
      "Epoch [100/150], Loss: 0.012322\n",
      "Epoch [120/150], Loss: 0.008019\n",
      "Epoch [140/150], Loss: 0.005823\n",
      "江西省: 准确率 73.98%\n",
      "Epoch [20/150], Loss: 0.020346\n",
      "Epoch [40/150], Loss: 0.010756\n",
      "Epoch [60/150], Loss: 0.015836\n",
      "Epoch [80/150], Loss: 0.007304\n",
      "Epoch [100/150], Loss: 0.008048\n",
      "Epoch [120/150], Loss: 0.003610\n",
      "Epoch [140/150], Loss: 0.002640\n",
      "山东省: 准确率 83.20%\n",
      "Epoch [20/150], Loss: 0.073712\n",
      "Epoch [40/150], Loss: 0.031105\n",
      "Epoch [60/150], Loss: 0.041229\n",
      "Epoch [80/150], Loss: 0.048585\n",
      "Epoch [100/150], Loss: 0.023712\n",
      "Epoch [120/150], Loss: 0.022700\n",
      "Epoch [140/150], Loss: 0.021300\n",
      "河南省: 准确率 73.79%\n",
      "Epoch [20/150], Loss: 0.015313\n",
      "Epoch [40/150], Loss: 0.022232\n",
      "Epoch [60/150], Loss: 0.014524\n",
      "Epoch [80/150], Loss: 0.015261\n",
      "Epoch [100/150], Loss: 0.012675\n",
      "Epoch [120/150], Loss: 0.015527\n",
      "Epoch [140/150], Loss: 0.011562\n",
      "湖北省: 准确率 76.66%\n",
      "Epoch [20/150], Loss: 0.080889\n",
      "Epoch [40/150], Loss: 0.033076\n",
      "Epoch [60/150], Loss: 0.019650\n",
      "Epoch [80/150], Loss: 0.030454\n",
      "Epoch [100/150], Loss: 0.013309\n",
      "Epoch [120/150], Loss: 0.023937\n",
      "Epoch [140/150], Loss: 0.010224\n",
      "湖南省: 准确率 78.21%\n",
      "Epoch [20/150], Loss: 0.069711\n",
      "Epoch [40/150], Loss: 0.033596\n",
      "Epoch [60/150], Loss: 0.011834\n",
      "Epoch [80/150], Loss: 0.037401\n",
      "Epoch [100/150], Loss: 0.017581\n",
      "Epoch [120/150], Loss: 0.016630\n",
      "Epoch [140/150], Loss: 0.014552\n",
      "广东省: 准确率 74.32%\n",
      "Epoch [20/150], Loss: 0.016691\n",
      "Epoch [40/150], Loss: 0.010309\n",
      "Epoch [60/150], Loss: 0.012958\n",
      "Epoch [80/150], Loss: 0.005426\n",
      "Epoch [100/150], Loss: 0.010738\n",
      "Epoch [120/150], Loss: 0.014526\n",
      "Epoch [140/150], Loss: 0.002953\n",
      "广西壮族自治区: 准确率 85.40%\n",
      "Epoch [20/150], Loss: 0.033184\n",
      "Epoch [40/150], Loss: 0.001997\n",
      "Epoch [60/150], Loss: 0.016922\n",
      "Epoch [80/150], Loss: 0.011417\n",
      "Epoch [100/150], Loss: 0.002398\n",
      "Epoch [120/150], Loss: 0.006387\n",
      "Epoch [140/150], Loss: 0.004022\n",
      "海南省: 准确率 77.87%\n",
      "Epoch [20/150], Loss: 0.018117\n",
      "Epoch [40/150], Loss: 0.007435\n",
      "Epoch [60/150], Loss: 0.006585\n",
      "Epoch [80/150], Loss: 0.017519\n",
      "Epoch [100/150], Loss: 0.003928\n",
      "Epoch [120/150], Loss: 0.009390\n",
      "Epoch [140/150], Loss: 0.008603\n",
      "重庆市: 准确率 73.51%\n",
      "Epoch [20/150], Loss: 0.013508\n",
      "Epoch [40/150], Loss: 0.011131\n",
      "Epoch [60/150], Loss: 0.007621\n",
      "Epoch [80/150], Loss: 0.012615\n",
      "Epoch [100/150], Loss: 0.010088\n",
      "Epoch [120/150], Loss: 0.012584\n",
      "Epoch [140/150], Loss: 0.013422\n",
      "四川省: 准确率 69.94%\n",
      "Epoch [20/150], Loss: 0.039786\n",
      "Epoch [40/150], Loss: 0.028744\n",
      "Epoch [60/150], Loss: 0.019301\n",
      "Epoch [80/150], Loss: 0.012008\n",
      "Epoch [100/150], Loss: 0.026747\n",
      "Epoch [120/150], Loss: 0.015139\n",
      "Epoch [140/150], Loss: 0.013739\n",
      "贵州省: 准确率 64.05%\n",
      "Epoch [20/150], Loss: 0.055441\n",
      "Epoch [40/150], Loss: 0.051541\n",
      "Epoch [60/150], Loss: 0.019734\n",
      "Epoch [80/150], Loss: 0.037409\n",
      "Epoch [100/150], Loss: 0.013136\n",
      "Epoch [120/150], Loss: 0.009409\n",
      "Epoch [140/150], Loss: 0.017731\n",
      "云南省: 准确率 70.57%\n",
      "Epoch [20/150], Loss: 0.016931\n",
      "Epoch [40/150], Loss: 0.008438\n",
      "Epoch [60/150], Loss: 0.011485\n",
      "Epoch [80/150], Loss: 0.010500\n",
      "Epoch [100/150], Loss: 0.011264\n",
      "Epoch [120/150], Loss: 0.008806\n",
      "Epoch [140/150], Loss: 0.003779\n",
      "西藏自治区: 准确率 67.31%\n",
      "Epoch [20/150], Loss: 0.011096\n",
      "Epoch [40/150], Loss: 0.015785\n",
      "Epoch [60/150], Loss: 0.012062\n",
      "Epoch [80/150], Loss: 0.006526\n",
      "Epoch [100/150], Loss: 0.014732\n",
      "Epoch [120/150], Loss: 0.005521\n",
      "Epoch [140/150], Loss: 0.004715\n",
      "陕西省: 准确率 84.90%\n",
      "Epoch [20/150], Loss: 0.046930\n",
      "Epoch [40/150], Loss: 0.010048\n",
      "Epoch [60/150], Loss: 0.013879\n",
      "Epoch [80/150], Loss: 0.012901\n",
      "Epoch [100/150], Loss: 0.011589\n",
      "Epoch [120/150], Loss: 0.008245\n",
      "Epoch [140/150], Loss: 0.024432\n",
      "甘肃省: 准确率 82.35%\n",
      "Epoch [20/150], Loss: 0.056927\n",
      "Epoch [40/150], Loss: 0.007530\n",
      "Epoch [60/150], Loss: 0.010984\n",
      "Epoch [80/150], Loss: 0.015757\n",
      "Epoch [100/150], Loss: 0.030403\n",
      "Epoch [120/150], Loss: 0.020360\n",
      "Epoch [140/150], Loss: 0.007968\n",
      "青海省: 准确率 70.46%\n",
      "Epoch [20/150], Loss: 0.006286\n",
      "Epoch [40/150], Loss: 0.006644\n",
      "Epoch [60/150], Loss: 0.005854\n",
      "Epoch [80/150], Loss: 0.008566\n",
      "Epoch [100/150], Loss: 0.010515\n",
      "Epoch [120/150], Loss: 0.007012\n",
      "Epoch [140/150], Loss: 0.001329\n",
      "宁夏回族自治区: 准确率 76.29%\n",
      "Epoch [20/150], Loss: 0.014800\n",
      "Epoch [40/150], Loss: 0.018304\n",
      "Epoch [60/150], Loss: 0.013201\n",
      "Epoch [80/150], Loss: 0.014450\n",
      "Epoch [100/150], Loss: 0.012574\n",
      "Epoch [120/150], Loss: 0.005520\n",
      "Epoch [140/150], Loss: 0.011935\n",
      "新疆维吾尔自治区: 准确率 71.59%\n",
      "\n",
      "平均预测准确率: 77.97%\n",
      "准确率 > 90% 的省份数量: 2\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "2a34160661aadd53"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "3bb7266dd40c861d"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "7c7cce8b798bac92"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "3fa4730b326832d1"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "4d9db12765a8e052"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "f53d580c02f9ac9"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "34c91bf687c95b62"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "336ec3996ade5dc3"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "7a0577f9d214e9b5"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "a3d0dd8b3b36fd51"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "739db2682a4932f9"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "2cd26de891a56631"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "27b49a4121a0511b"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
